package org.zeapp.opencloud.framework.synchro;

import java.util.UUID;

/**
 * This class represent the mapping between an alias and a local folder. An
 * alias can be seen as a root directory. Each stored data is stored as relative
 * path to its alias.
 * 
 * @author Amphiprion
 * 
 */
public class FolderAlias {
	private String uid;
	private String name = "";
	private String localPath = "";

	/**
	 * Create a new FolderAlias object. The UID is auto generated using
	 * "UUID.randomUUID().toString()"
	 */
	public FolderAlias() {
		uid = UUID.randomUUID().toString();
	}

	/**
	 * Create a new FolderAlias object without local mapping (used for
	 * retrieving existing folder alias in the cloud).
	 * 
	 * @param uid
	 *            the uid
	 * @param name
	 *            the displayed name
	 */
	public FolderAlias(String uid, String name) {
		this(uid, name, null);
	}

	/**
	 * Create a new FolderAlias object.
	 * 
	 * @param uid
	 *            the uid
	 * @param name
	 *            the displayed name
	 * @param localPath
	 *            the local path mapping
	 */
	public FolderAlias(String uid, String name, String localPath) {
		this.uid = uid;
		this.name = name;
		this.localPath = localPath;
	}

	/**
	 * @return the name
	 */
	public String getName() {
		return name;
	}

	/**
	 * @param name
	 *            the name to set
	 */
	public void setName(String name) {
		this.name = name;
	}

	/**
	 * @return the localPath
	 */
	public String getLocalPath() {
		return localPath;
	}

	/**
	 * @param localPath
	 *            the localPath to set
	 */
	public void setLocalPath(String localPath) {
		this.localPath = localPath;
	}

	/**
	 * @return the uid
	 */
	public String getUid() {
		return uid;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + (uid == null ? 0 : uid.hashCode());
		return result;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		FolderAlias other = (FolderAlias) obj;
		if (uid == null) {
			if (other.uid != null) {
				return false;
			}
		} else if (!uid.equals(other.uid)) {
			return false;
		}
		return true;
	}

}
